package com.ruoyi.web.controller.common.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ErpConsumables;
import com.ruoyi.system.service.IErpConsumablesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 耗材管理Controller
 * 
 * @author ruoyi
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/system/consumables")
public class ErpConsumablesController extends BaseController
{
    @Autowired
    private IErpConsumablesService erpConsumablesService;

    /**
     * 查询耗材管理列表
     */
//    @PreAuthorize("@ss.hasPermi('system:consumables:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpConsumables erpConsumables)
    {
        startPage();
        List<ErpConsumables> list = erpConsumablesService.selectErpConsumablesList(erpConsumables);
        return getDataTable(list);
    }

    /**
     * 导出耗材管理列表
     */
//    @PreAuthorize("@ss.hasPermi('system:consumables:export')")
    @Log(title = "耗材管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpConsumables erpConsumables)
    {
        List<ErpConsumables> list = erpConsumablesService.selectErpConsumablesList(erpConsumables);
        ExcelUtil<ErpConsumables> util = new ExcelUtil<ErpConsumables>(ErpConsumables.class);
        util.exportExcel(response, list, "耗材管理数据");
    }

    /**
     * 获取耗材管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:consumables:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(erpConsumablesService.selectErpConsumablesById(id));
    }

    /**
     * 新增耗材管理
     */
//    @PreAuthorize("@ss.hasPermi('system:consumables:add')")
    @Log(title = "耗材管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpConsumables erpConsumables)
    {
        return toAjax(erpConsumablesService.insertErpConsumables(erpConsumables));
    }

    /**
     * 修改耗材管理
     */
//    @PreAuthorize("@ss.hasPermi('system:consumables:edit')")
    @Log(title = "耗材管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpConsumables erpConsumables)
    {
        return toAjax(erpConsumablesService.updateErpConsumables(erpConsumables));
    }

    /**
     * 删除耗材管理
     */
//    @PreAuthorize("@ss.hasPermi('system:consumables:remove')")
    @Log(title = "耗材管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(erpConsumablesService.deleteErpConsumablesByIds(ids));
    }
}
